//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2013 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_FUNCTORS_PREDICATES_CHAR_H_
#define _BUOLA_FUNCTORS_PREDICATES_CHAR_H_

#include <buola/functors/predicates/unary.h>
#include <buola/utility/ulocale.h>
#include <unicode/uchar.h>

namespace buola { namespace fn {

///\addtogroup functors
///@{

///\name Character classification predicates
//@{

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// isspace ASCII predicate
///
/// Evaluated with a single argument, returns true if the parameter is an ASCII space
///
/////////////////////////////////////////////////////////////////////////////////////////////////
struct AIsAsciiAlnum : public GUnaryPredicate
{
    ///returns true if the character is of the given type
    bool operator()(wchar_t pCh) const
    {
        if(pCh>127) return false;
        return isalnum(pCh);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// isspace ASCII predicate
///
/// Evaluated with a single argument, returns true if the parameter is an ASCII space
///
/////////////////////////////////////////////////////////////////////////////////////////////////
struct AIsAsciiAlpha : public GUnaryPredicate
{
    ///returns true if the character is of the given type
    bool operator()(wchar_t pCh) const
    {
        if(pCh>127) return false;
        return isalpha(pCh);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// isspace ASCII predicate
///
/// Evaluated with a single argument, returns true if the parameter is an ASCII space
///
/////////////////////////////////////////////////////////////////////////////////////////////////
struct AIsAsciiCntrl : public GUnaryPredicate
{
    ///returns true if the character is of the given type
    bool operator()(wchar_t pCh) const
    {
        if(pCh>127) return false;
        return iscntrl(pCh);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// isspace ASCII predicate
///
/// Evaluated with a single argument, returns true if the parameter is an ASCII space
///
/////////////////////////////////////////////////////////////////////////////////////////////////
struct AIsAsciiDigit : public GUnaryPredicate
{
    ///returns true if the character is of the given type
    bool operator()(wchar_t pCh) const
    {
        if(pCh>127) return false;
        return isdigit(pCh);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// isspace ASCII predicate
///
/// Evaluated with a single argument, returns true if the parameter is an ASCII space
///
/////////////////////////////////////////////////////////////////////////////////////////////////
struct AIsAsciiLower : public GUnaryPredicate
{
    ///returns true if the character is of the given type
    bool operator()(wchar_t pCh) const
    {
        if(pCh>127) return false;
        return islower(pCh);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// isspace ASCII predicate
///
/// Evaluated with a single argument, returns true if the parameter is an ASCII space
///
/////////////////////////////////////////////////////////////////////////////////////////////////
struct AIsAsciiPrint : public GUnaryPredicate
{
    ///returns true if the character is of the given type
    bool operator()(wchar_t pCh) const
    {
        if(pCh>127) return false;
        return isprint(pCh);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// isspace ASCII predicate
///
/// Evaluated with a single argument, returns true if the parameter is an ASCII space
///
/////////////////////////////////////////////////////////////////////////////////////////////////
struct AIsAsciiSpace : public GUnaryPredicate
{
    ///returns true if the character is of the given type
    bool operator()(wchar_t pCh) const
    {
        if(pCh>127) return false;
        return isspace(pCh);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// isspace ASCII predicate
///
/// Evaluated with a single argument, returns true if the parameter is an ASCII space
///
/////////////////////////////////////////////////////////////////////////////////////////////////
struct AIsAsciiUpper : public GUnaryPredicate
{
    ///returns true if the character is of the given type
    bool operator()(wchar_t pCh) const
    {
        if(pCh>127) return false;
        return isupper(pCh);
    }
};

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// isspace ASCII predicate
///
/// Evaluated with a single argument, returns true if the parameter is an ASCII space
///
/////////////////////////////////////////////////////////////////////////////////////////////////
struct AIsAsciiXDigit : public GUnaryPredicate
{
    ///returns true if the character is of the given type
    bool operator()(wchar_t pCh) const
    {
        if(pCh>127) return false;
        return isxdigit(pCh);
    }
};

///returns a predicate that returns true if its argument is alphanumeric
inline AIsAsciiAlnum is_ascii_alnum()
{
    return {};
}

///returns a predicate that returns true if its argument is a letter
inline AIsAsciiAlpha is_ascii_alpha()
{
    return {};
}

///returns a predicate that returns true if its argument is a control character
inline AIsAsciiCntrl is_ascii_cntrl()
{
    return {};
}

///returns a predicate that returns true if its argument is a digit
inline AIsAsciiDigit is_ascii_digit()
{
    return {};
}

///returns a predicate that returns true if its argument is a lowercase letter
inline AIsAsciiLower is_ascii_lower()
{
    return {};
}

///returns a predicate that returns true if its argument is a printable character
inline AIsAsciiPrint is_ascii_print()
{
    return {};
}

///returns a predicate that returns true if its argument is a space
inline AIsAsciiSpace is_ascii_space()
{
    return {};
}

///returns a predicate that returns true if its argument is an uppercase letter
inline AIsAsciiUpper is_ascii_upper()
{
    return {};
}

///returns a predicate that returns true if its argument is an hexadecimal digit (typed version)
inline AIsAsciiXDigit is_ascii_xdigit()
{
    return {};
}

//@}

///@}

/*namespace fn*/ } /*namespace buola*/ }

#endif
